package com.melodyframe.stage.core.channel;

import java.util.Iterator;

import com.melodyframe.common.context.Context;
import com.melodyframe.stage.core.performer.Performer;

public class CommonChannel implements Channel {
	private Iterator<Performer>	performerChain;

	public CommonChannel(Iterator<Performer> performerChain) {
		this.performerChain = performerChain;
	}

	@Override
	public void perform(Context context) {
		if (this.performerChain.hasNext()) {
			Performer performer = this.performerChain.next();
			this.invokeAction(performer, context);
		}
	}

	public void invokeAction(Performer performer, Context context) {
		try {
			performer.perform(context);
			this.perform(context);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	public Iterator<Performer> getActionChain() {
		return performerChain;
	}

	public void setActionChain(Iterator<Performer> performerChain) {
		this.performerChain = performerChain;
	}

}
